{% extends("common/base.html")%}
{% block title %} 权限管理系统 {% endblock %}
{% block head %}
<style>
    html,
    body {
        background-color: #F1F1F1;
        margin: 0;
        padding: 0;
    }

    .layui-fluid {
        padding: 15px;
    }
</style>
{% endblock %}

{% block body %}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" style="padding-top: 20px;" data-url="{{url_for('menu.add')}}" method="post">
                {{form.csrf_token}}
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: #f00;">*</span> 所属菜单：</label>
                    <div class="layui-input-block">
                        <select name="parent_id">
                            <option value="0">顶级菜单</option>
                            {% for auth in menu %}
                            <option value="{{auth.id}}" {% if parent and auth.id==parent.id%} selected {% endif %}>{{auth.level | my_repeat}}{{auth.name}}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: #f00;">*</span> 菜单：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off"
                            placeholder="请输入菜单" class="layui-input" value=""
                            lay-verify="required" lay-reqtext="菜单是必填项">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">路由：</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" placeholder="" autocomplete="off" class="layui-input"
                            value="">
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label">图标：</label>
                    <div class="layui-input-block">
                        <input type="text" name="icon" placeholder="" autocomplete="off" class="layui-input"
                            value="">
                    </div>
                </div> -->
                <div class="layui-form-item">
                    <label class="layui-form-label">状态：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="启用" checked>
                        <input type="radio" name="status" value="0" title="停用">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序：</label>
                    <div class="layui-input-block">
                        <input type="number" name="sort" placeholder="" autocomplete="off" class="layui-input"
                            value="0">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否导航：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked value="1" lay-skin="switch" lay-filter="switchMenu"
                            lay-text="是|否">
                        <input type="hidden" name="is_menu" value="1" id="is_menu">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="siteInfo">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'element'], function () {
        var form = layui.form;
        var element = layui.element;
        //监听指定开关
        form.on('switch(switchMenu)', function (data) {
            let value = this.checked ? 1 : 0;
            document.getElementById("is_menu").value = value;
        });
        //监听信息提交
        form.on('submit(siteInfo)', function (data) {
            doAjaxSubmit($(".layui-form"))
            return false;
        });
    });
</script>
{% endblock %}